package com.hewep.demo.device.mina.core.message;

import java.util.Arrays;

import com.hewep.demo.device.directive.DeviceCmd;
import com.hewep.demo.device.mina.core.Request;

public class BasicRequest extends AbstractMessage implements Request {
	
	private String method;
	private byte[] header;  //包头
	private byte[] sweep;   //扫码器编码
	private byte[] mark;    //有效数据标志位
	
	public String getMethod() {		
		return method;
	}	
	
	public byte[] getHeader(){
		return this.header;
	}
	public byte[] getSweep() {
		return sweep;
	}

	public void setSweep(byte[] sweep) {
		this.sweep = sweep;
	}

	public byte[] getMark() {
		return mark;
	}

	public void setMark(byte[] mark) {
		this.mark = mark;
	}

	public void setHeader(byte[] header) {
		this.header = header;
	}

	public void parseData(){
		String cmd = "";
		byte[] datas = this.getData();
		this.setHeader(Arrays.copyOf(datas, 2));  // 解析包头
		
		if(Arrays.equals(this.header, DeviceCmd.REQUEST_ALL.getHeader())){
			this.setSweep(Arrays.copyOfRange(this.getData(), 2, 6));  // 解析点菜器编号
			this.setMark(Arrays.copyOfRange(datas, 8, 9));   // 解析 标志位
			if(Arrays.equals(DeviceCmd.REQUEST_ALL_DOWNLOAD.getHeader(), mark)){
				
			}
			if(mark == null){
				cmd = DeviceCmd.REQUEST_ALL.getCmd();
			}else{
				cmd = DeviceCmd.valueOf(mark).getCmd();
			}
		}else{
			cmd = DeviceCmd.valueOf(header).getCmd();
		}
		
		this.setCmd(cmd);
	}

}
